package com.xintonghua.bussiness.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.base.SimpleBaseAdapter;
import com.xintonghua.bussiness.ui.user.BigImagePagerActivity;
import com.xintonghua.bussiness.util.GlideUtils;
import com.xintonghua.bussiness.util.ImageTools;
import com.xintonghua.bussiness.util.MyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/1/24.
 * 包名：com.xintonghua.meirang.ui.adapter
 */

public class ImageAdapter extends SimpleBaseAdapter<String> {

    public ImageAdapter(List<String> list, Context context) {
        super(list, context);
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        RankingViewHolder viewHolder;
        if (view == null) {
            view = mInflater.inflate(R.layout.adapter_image, null);
            viewHolder = new RankingViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (RankingViewHolder) view.getTag();
        }
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MyUtils.getWidth(context) / 3 - MyUtils.dip2px(context, 24), MyUtils.getWidth(context) / 3 - MyUtils.dip2px(context, 24));
        viewHolder.itemImage.setLayoutParams(params);
        GlideUtils.load(context, viewHolder.itemImage, mList.get(i));
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.addAll(mList);
                bundle.putStringArrayList(BigImagePagerActivity.INTENT_IMGURLS, arrayList);
                bundle.putString(BigImagePagerActivity.INTENT_POSITION, String.valueOf(i));
                MyUtils.openActivity(context, BigImagePagerActivity.class, bundle);
            }
        });
        return view;
    }


    static class RankingViewHolder {
        @BindView(R.id.item_image)
        ImageView itemImage;

        public RankingViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
